package org.yu.team2023.flashdays;

import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.yu.team2023.flashdays.blockentity.TreasureUpgradeBlock;
import org.yu.team2023.flashdays.blockentity.TreasureUpgradeEntity;
import org.yu.team2023.flashdays.blockentity.TreasureUpgradeMenu;
import org.yu.team2023.flashdays.blockentity.TreasureUpgradeScreen;
import org.yu.team2023.flashdays.registries.SimpleReg;

public class ModBlockEntities {
    public static class Blocks{
        private static final SimpleReg BLOCK=FlashDays.getSimpleReg();
        public static final RegistryObject<TreasureUpgradeBlock> TREASURE_UPGRADE=BLOCK.block("treasure_upgrade",TreasureUpgradeBlock::new).lang("强化站").cubeModel().build();
        private static void init(){

        }
    }
    public static class BlockEntities{
        private static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPE= DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES,FlashDays.MODID);
        public static final RegistryObject<BlockEntityType<TreasureUpgradeEntity>> TREASURE_UPGRADE_ENTITY=BLOCK_ENTITY_TYPE.register("treasure_upgrade",()->BlockEntityType.Builder.<TreasureUpgradeEntity>of(TreasureUpgradeEntity::new,Blocks.TREASURE_UPGRADE.get()).build(null));
    }
    public static class MenuTypes{
        private static final DeferredRegister<MenuType<?>> MENU_TYPE= DeferredRegister.create(ForgeRegistries.MENU_TYPES,FlashDays.MODID);
        public static final RegistryObject<MenuType<TreasureUpgradeMenu>> TREASURE_UPGRADE_MENU=MENU_TYPE.register("treasure_upgrade",()-> IForgeMenuType.create(TreasureUpgradeMenu::new));
    }

    public static void init(){
        var bus= FMLJavaModLoadingContext.get().getModEventBus();
        Blocks.init();
        BlockEntities.BLOCK_ENTITY_TYPE.register(bus);
        MenuTypes.MENU_TYPE.register(bus);
    }

    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD,modid = FlashDays.MODID)
    public static class ClientHandle {
        @SubscribeEvent
        public static void onClientSetup(FMLClientSetupEvent event){
            event.enqueueWork(() -> MenuScreens.register(MenuTypes.TREASURE_UPGRADE_MENU.get(), TreasureUpgradeScreen::new));
        }
    }
}
